package com.jifujun.fastdfs_springboot.dao;

import com.jifujun.fastdfs_springboot.model.FastDFS;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Create with IntelliJ IDEA
 * Project Name: fast_dfs
 * Package Name: com.jifujun.fast_dfs.dao
 * Date: 2018/3/2713:26
 * User: 快乐的小菌菌
 * Description:
 */
@Mapper
public interface FastDFSDao {

    @Insert("INSERT INTO fastdfs (group_name, storage_path, ext_name, size, file_name, using_type) VALUES (#{group_name},#{storage_path},#{ext_name},#{size},#{file_name},1);")
    void save(FastDFS fastDFS);

    @Select("SELECT * FROM fastdfs;")
    List<FastDFS> queryList();

    @Select("SELECT count(*) FROM fastdfs;")
    List<FastDFS> countForQueryList();

    @Select("SELECT * FROM fastdfs where id = #{id} and using_type = 1;")
    FastDFS getById(@Param("id") Integer id);

    @Delete("UPDATE FROM fastdfs SET using_type = 0 WHERE id = #{id}")
    void deleteById(@Param("id") Integer id);

    @Select("SELECT * FROM fastdfs where group_name = #{arg0} and storage_path = #{arg1};")
    FastDFS getByPath(String groupName, String storagePath);

    @Delete("UPDATE fastdfs SET using_type = 0 WHERE group_name = #{arg0} and storage_path = #{arg1};")
    void deleteByPath(String groupName, String storagePath);
}
